<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Start extends MN_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('ion_auth');
        $this->load->library('session');
        $this->load->library('form_validation');
        $this->load->helper('url');

        // Load MongoDB library instead of native db driver if required
        //$this->config->item('use_mongodb', 'ion_auth') ?
        //$this->load->library('mongo_db') :
        $this->load->database();

        $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
    }

    public function index() {

        if (!$this->ion_auth->logged_in()) {
            //redirect them to the login page
            redirect('auth/login', 'refresh');
        } elseif (!$this->ion_auth->is_members()) {
            //echo ("Es un miembro");//redirect them to the home page because they must be an administrator to view this
            //echo $this->ion_auth->get_user_idepers();
            //echo $this->ion_auth->get_user_username();
            //print_r($this->session->userdata);
            
           //$this->_render('docentes/start');
           redirect('docente/inicio');
        } else {
            //set the flash data error message if there is one
            
            //$this->_render('home/inicio');
            echo ("Es un administrador");
            echo $this->ion_auth->get_user_idepers();
            echo $this->ion_auth->get_user_username();
            print_r($this->session->userdata);
        }
        //redirect('auth', 'refresh');
        //$this->_render('home/inicio');
    }

    public function login() {
        $this->_render('institucion/start');
        //redirect('auth', 'refresh');
    }

    public function logout() {
        redirect('auth/logout', 'refresh');
    }
    
 public function inicio() {
     $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
            $this->data['users'] = $this->ion_auth->users()->result();
            foreach ($this->data['users'] as $k => $user) {
                $this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
            }
            

           $this->_render('auth/index', 'refresh');
        
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
